﻿using System.Collections.Generic;
using UnityEngine;

/**
 * 状态管理器
 */

public class StateMgr : MonoBehaviour{

    private Dictionary<AniState, IState> fsm = new Dictionary<AniState, IState>();

    public void Init(){
        fsm.Add(AniState.Born, new StateBorn());
        fsm.Add(AniState.Idle, new StateIdle());
        fsm.Add(AniState.Move, new StateMove());
        fsm.Add(AniState.Attack, new StateAttack());
        fsm.Add(AniState.Die, new StateDie());
        fsm.Add(AniState.Hit, new StateHit());
        PECommon.Log("Init StateMgr done");
    }

    public void ChangeState(EntityBase entity, AniState targetState, params object[] args){
        if (entity.currentAnimState == targetState){
            return;
        }

        if (fsm.ContainsKey(targetState)){
            if (entity.currentAnimState != AniState.None){
                fsm[entity.currentAnimState].Exit(entity, args);
            } 
            fsm[targetState].Enter(entity, args);
            
            fsm[targetState].Process(entity, args);
            
            entity.currentAnimState = targetState;
        }
    }
}
